package com.xiyi_design.printer_manage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiyi_design.printer_manage.service.BaseService;
import tk.mybatis.mapper.common.Mapper;

import java.io.Serializable;
import java.util.List;

public abstract class BaseServiceImpl<T> implements BaseService<T> {

    protected abstract Mapper<T> getReadMapper();
    protected abstract Mapper<T> getWriteMapper();

    @Override
    public int save(T t) {
        int iRet = getWriteMapper().insert(t);
        return iRet;
    }

    @Override
    public int update(T t) {
        int iRet = getWriteMapper().updateByPrimaryKeySelective(t);
        return iRet;
    }

    @Override
    public int deleteById(Serializable id) {
        int iRet = getWriteMapper().deleteByPrimaryKey(id);
        return iRet;
    }

    @Override
    public T getById(Serializable id) {
        return getReadMapper().selectByPrimaryKey(id);
    }

    @Override
    public List<T> getList() {
        return getReadMapper().selectAll();
    }

    @Override
    public PageInfo<T> getListByPage(int pageNo, int pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<T> list = this.getList();
        return new PageInfo<T>(list);
    }


}
